package com.cens.mall.order.config;

import com.cens.mall.order.entity.OrderEntity;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;
import java.util.HashMap;

@Configuration
public class MQInitConfig {

    @Bean
    public Queue orderDelayQueue() {
        HashMap<String, Object> args = new HashMap<>();
        args.put("x-dead-letter-exchange", "order-event-exchange");
        args.put("x-dead-letter-routing-key", "order.release.order");
        args.put("x-message-ttl", 60000);
        return new Queue("order-delay-queue", true, false, false, args);
    }

    @Bean
    public Queue orderReleaseQueue() {
        return new Queue("order-release-queue", true, false, false);
    }

    public Queue orderSeckillQueue(){
        return new Queue("order-seckill-queue", true, false, false);
    }


    @Bean
    public Exchange orderEventExchange() {
        return new TopicExchange("order-event-exchange", true, false);
    }

    @Bean
    public Binding orderCreateBinding() {
        return new Binding("order-delay-queue", Binding.DestinationType.QUEUE,
                "order-event-exchange", "order.create.order", null);
    }

    @Bean
    public Binding orderReleaseBinding() {
        return new Binding("order-release-queue", Binding.DestinationType.QUEUE,
                "order-event-exchange", "order.release.order", null);
    }

    @Bean
    public Binding orderReleaseOtherBinding(){
        return new Binding("stock-release-stock-queue", Binding.DestinationType.QUEUE,
                "order-event-exchange","order.release.other.#",null);
    }

    public Binding orderSeckillBinding(){
        return new Binding("order-seckill-queue", Binding.DestinationType.QUEUE,
                "order-event-exchange","order.seckill.order",null);
    }

}
